package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.BroAndPaInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/14.
 */
public class BroAndPaAdapter extends BaseAdapter {
    private List<BroAndPaInfo> broAndPaInfos;
    private Context context;
    private SharedPreferences sp;
    private String id;
    private String role_id;
    public BroAndPaAdapter(List<BroAndPaInfo> broAndPaInfos, Context context) {
        this.broAndPaInfos = broAndPaInfos;
        this.context = context;
    }


    @Override
    public int getCount() {
        return broAndPaInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return broAndPaInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (holder==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_broandpa,null);
            holder.iv= (ImageView) convertView.findViewById(R.id.iv);
            holder.tv= (TextView) convertView.findViewById(R.id.tv);
            holder.ll_item= (LinearLayout) convertView.findViewById(R.id.ll_item);

           convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        sp=context.getSharedPreferences("heroid", Context.MODE_PRIVATE);
        id=sp.getString("hero","1");
        BroAndPaInfo ssi =broAndPaInfos.get(position);

        if (ssi.getRole_id().equals("1")&&ssi.getRelation().equals("pa")){
            Picasso.with(context).load(ssi.getTarget_role_pic_url()).into(holder.iv);
            holder.tv.setText(ssi.getDesc());

        }else {
            holder.ll_item.setVisibility(View.GONE);

        }


        return convertView;
    }
    private class ViewHolder {
        private ImageView iv;
        private TextView tv;
        private LinearLayout ll_item;
    }
}
